package com.cn.aam.checaiduo.ui.me;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.widget.TextView;

import com.cn.aam.checaiduo.AppData;
import com.cn.aam.checaiduo.R;
import com.cn.aam.checaiduo.backend.RetrofitHome;
import com.cn.aam.checaiduo.backend.rx.RxSchedulers;
import com.cn.aam.checaiduo.base.BaseActivity;
import com.cn.aam.checaiduo.base.ToolBarManager;
import com.cn.aam.checaiduo.bean.base.BaseResponseB;
import com.cn.aam.checaiduo.bean.me.NoticeB;
import com.cn.aam.checaiduo.utils.CalendarUtil;

import butterknife.BindView;

/**
 * monker on 2017/6/15.
 */

public class MessageDetailActivity extends BaseActivity {

    @BindView(R.id.notice_tv_title)
    TextView noticeTvTitle;
    @BindView(R.id.notice_tv_content)
    TextView noticeTvContent;
    @BindView(R.id.notice_tv_date)
    TextView noticeTvDate;
    private NoticeB noticeB;

    private final String STATE_HAS_READ = "1";


    public static Intent newInstance(Context context, NoticeB bean, String title) {
        Intent intent = new Intent(context, MessageDetailActivity.class);
        intent.putExtra("bean", bean);
        intent.putExtra("title", title);
        return intent;
    }

    @Override
    protected int layoutId() {
        return R.layout.activity_message_detail;
    }

    @Override
    protected void initView() {

        String title = getIntent().getStringExtra("title");
        ToolBarManager.with(this, WMContent).setTitle(title).setTitleColor(R.color.textColor)
                .setNavigationIcon(R.drawable.ic_nav_arrow_back)
                .setBackgroundColor(R.color.toolbar_bg_grey);

        noticeB = (NoticeB) getIntent().getSerializableExtra("bean");
        noticeTvTitle.setText(noticeB.getTitle());
        noticeTvContent.setText(noticeB.getContent());
        noticeTvDate.setText(CalendarUtil.getDate5(noticeB.getCreate_time()));
        gotoPointMall();
    }

    /**
     * 时间：2017/6/15
     * 描述：消息已经阅读
     */
    private void gotoPointMall() {

        //如果消息已读，则不调用
        if (TextUtils.equals(STATE_HAS_READ, noticeB.getStatus())) {
            return;
        }
        //修改消息为已读状态
        RetrofitHome.getInstance()
                .getInternalApi()
                .readNotify(AppData.getToken(), noticeB.getId())
                .compose(RxSchedulers.<BaseResponseB>toMain())
                .subscribe();

    }


}